#!/usr/bin/env python
#-*- coding:utf-8 -*-

from django.shortcuts import render_to_response,HttpResponse,redirect
from rest_framework import routers
from snippets.views import *
from datareport.views import *
def process(request, **args):
        '''接收所有匹配url的请求，根据请求url中的参数，通过反射动态指定view中的方法'''

        app = args.get('app', None)
        function = args.get('function', None)

        try:
                app_obj = __import__(app, fromlist=['views',])
                view_obj = getattr(app_obj, 'views')
                func_obj = getattr(view_obj, function)

                print func_obj
        except (ImportError, AttributeError), e:
	        pass 
                #router = routers.DefaultRouter()
                #router.register(r'Adinfo', AdinfoViewSet, base_name="Adinfo")
                #router.register(r'machine',machineViewSet,base_name="machine")
                #导入失败时，自定义404错误
                #return HttpResponse('<p>404 Not Found</p>')
        except Exception, e:
                return HttpResponse('<p>404 Not Found</p>')


        return func_obj(request, args)


